package com.sfcms.consumer.controller;

import com.sfcms.consumer.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class NewsContoller {

    private static final String REST_URL_PREFIX = "http://localhost:9003";//provider url

    @Autowired
    NewsService newsService;

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    HttpHeaders httpHeaders;


    @GetMapping("/findAll")
    public String findAll() {
        return newsService.findAll();
    }

    @GetMapping("/findAll2")
    public String findAll2() {
        return restTemplate.exchange(REST_URL_PREFIX + "/findAll", HttpMethod.GET,new HttpEntity<Object>(httpHeaders),String.class).getBody();
    }
}
